<script src="<?php echo Yii::app()->request->baseUrl; ?>/js/media/mediaelement.js"></script>
<link href="<?php echo Yii::app()->request->baseUrl; ?>/js/plugins/datatables/DT_bootstrap.css" rel="stylesheet">
<link href="<?php echo Yii::app()->request->baseUrl; ?>/js/plugins/responsive-tables/responsive-tables.css" rel="stylesheet">
<link href="<?php echo Yii::app()->request->baseUrl; ?>/js/plugins/lightbox/themes/evolution-dark/jquery.lightbox.css" rel="stylesheet">   
<script src="<?php echo Yii::app()->request->baseUrl; ?>/js/plugins/datatables/jquery.dataTables.js"></script>
<script src="<?php echo Yii::app()->request->baseUrl; ?>/js/plugins/datatables/DT_bootstrap.js"></script>
<script src="<?php echo Yii::app()->request->baseUrl; ?>/js/plugins/responsive-tables/responsive-tables.js"></script>
<script src="<?php echo Yii::app()->request->baseUrl; ?>/js/plugins/lightbox/jquery.lightbox.min.js"></script>
<div id="page-title" class="clearfix">
	<ul class="breadcrumb">
		<li>
			<?php echo CHtml::link('Home',array('/site/index')); ?><span class="divider">/</span>
		</li>
		<li>
			<?php echo CHtml::link('Film:'.$film->title.'',array('/film/update','id'=>$film->id)); ?><span class="divider">/</span>
		</li>
		<li class="active">Link List - (<?php echo CHtml::link('Episode:'.$episode->name.'',array('/episode/admin','fid'=>$film->id)); ?>)</li>
	</ul>		
</div> <!-- /.page-title -->
<?php
Yii::app()->clientScript->registerScript('search', "
$('.search-button').click(function(){
	$('.search-form').toggle();
	return false;
});
$('.search-form form').submit(function(){
	$.fn.yiiGridView.update('link-grid', {
		data: $(this).serialize()
	});
	return false;
});
");
?>
<?php echo CHtml::link('Advanced Search','#',array('class'=>'search-button hide')); ?>
<div class="search-form" style="display:none">
<?php $this->renderPartial('_search',array(
	'model'=>$model,
)); ?>
</div><!-- search-form -->
<div class="widget">
<div class="widget-toolbar">
	<?php echo CHtml::link('<i class="icon-step-backward"></i> Back',array('/episode/admin','fid'=>$episode->fid),array('class'=>'btn btn-primary')); ?>
	<?php echo CHtml::link('<i class="icon-film"></i> Create Link',array('/link/create','eid'=>$episode->id),array('class'=>'btn btn-primary')); ?>
</div> <!-- /.widget-toolbar -->
</div>

<div class="widget widget-table">
	<div class="widget-header">						
		<h3>
			<i class="icon-th-list"></i>
			<?php echo 'Link List - '.CHtml::link('Episode:'.$episode->name.'',array('/episode/admin','fid'=>$film->id)).' - '.CHtml::link('Film:'.$film->title.'',array('/film/update','id'=>$film->id)); ?>			
		</h3>
	</div> <!-- /widget-header -->
	<div class="widget-content">
<?php $form=$this->beginWidget('CActiveForm', array(
    'enableAjaxValidation'=>true,
)); ?>
<?php $this->widget('zii.widgets.grid.CGridView', array(
	'id'=>'link-grid',
	'dataProvider'=>$model->search(),
	'summaryText'=>'',
	'htmlOptions'=>array('class'=>'table table-striped table-bordered responsive','style'=>'width:"100% !important"'),
	'columns'=>array(
		array(
            'id'=>'autoId',
            'class'=>'CCheckBoxColumn',
            'selectableRows' => '50',   
        ),
		array(
            'name'=>'name',
            //'value'=>'$data->name',
            'type'=>'raw',
            'value'=>'"<a data=\"".$data->link."\" href=\"#myModal\" class=\"btn\" data-toggle=\"modal\">".
			CHtml::image(Yii::app()->request->baseUrl."/images/icons/player-icon.png","player-icon.png",array("style"=>"max-width:60px;"))." ".$data->name."</a>"',
			'htmlOptions'=>array("width"=>"35%"),
        ),
		array(
            'name'=>'Episode',
            'value'=>'$data->episode[0]["name"]',
			'htmlOptions'=>array("width"=>"32%"),
        ),
//        array(
//            'name'=>'link',
//            'value'=>'$data->link',
//			'htmlOptions'=>array("width"=>"35%"),
//        ),
//		'link',
//		'isdefault',
        array(
            'name'=>'isdefault',
            'header'=>'Default',
            'value'=>'($data->isdefault=="1")?("Yes"):("No")',
            'htmlOptions'=>array("width"=>"30px"),
        ),
         array(
            'name'=>'isdie',
            'header'=>'Link Die',
            'value'=>'($data->isdie=="1")?("Yes"):("No")',
         	'htmlOptions'=>array("width"=>"55px"),
        ),
		array(
			'header'=>'Action',
			'class'=>'CButtonColumn',
			'buttons'=>array(
        		
		        'delete' => array
		        (
		            'label'=>'Delete',
		        	'imageUrl'=>Yii::app()->request->baseUrl.'/images/icons/delete-file-icon_24.png',
		        	'url'=>'Yii::app()->createUrl("link/delete", array("id"=>$data->id))',
		        ),
		        'update' => array
		        (
		            'label'=>'Update',
		        	'imageUrl'=>Yii::app()->request->baseUrl.'/images/icons/table-edit-icon_24.png',
		            'url'=>'Yii::app()->createUrl("link/update", array("id"=>$data->id))',
		        ),
		        'view' => array
		        (
		            'label'=>'View Video',
		        	'imageUrl'=>Yii::app()->request->baseUrl.'/images/icons/player-icon.png',
		            'url'=>'#myModal',
		        	'options'=>array("class"=>"btn",'data-toggle'=>'modal','data'=>'$data->link'),
		        	'visible'=>'false',
		        ),
        	),
			'htmlOptions'=>array("width"=>"80px"),
        ),
	),
)); ?>
<script>
function reloadGrid(data) {
    $.fn.yiiGridView.update('link-grid');
}

</script>
		<div style="padding-top: 10px;border-top: 1px solid #cccccc;padding-left: 20px;">
		<?php echo CHtml::ajaxSubmitButton('Filter',array('link/ajaxupdate'), array(),array("style"=>"display:none;")); ?>
		<?php echo CHtml::ajaxSubmitButton('Default',array('link/ajaxupdate','act'=>'doDefault'), array('success'=>'reloadGrid'),array('class'=>'btn btn-success','style'=>'margin-right:20px;')); ?>
		<?php echo CHtml::ajaxSubmitButton('Normal',array('link/ajaxupdate','act'=>'doNormal'), array('success'=>'reloadGrid'),array('class'=>'btn btn-warning','style'=>'margin-right:20px;')); ?>
		<?php echo CHtml::ajaxSubmitButton('Not Die',array('link/ajaxupdate','act'=>'doNodie'), array('success'=>'reloadGrid'),array('class'=>'btn btn-success','style'=>'margin-right:20px;')); ?>
		<?php echo CHtml::ajaxSubmitButton('Is Die',array('link/ajaxupdate','act'=>'doDie'), array('success'=>'reloadGrid'),array('class'=>'btn btn-warning','style'=>'margin-right:20px;')); ?>
		<?php echo CHtml::ajaxSubmitButton('Delete',array('link/ajaxupdate','act'=>'doDelete'), array('success'=>'reloadGrid'),array('class'=>'btn btn-danger','style'=>'margin-right:20px;')); ?>
		</div>
		<?php $this->endWidget(); ?>
	</div> <!-- /widget-content -->
</div> <!-- /widget -->

<div class="modal fade hide" id="myModal">
  <div class="modal-header">
    <button type="button" class="close" data-dismiss="modal">&times;</button>
    <h3>Video</h3>
  </div>
  <div class="modal-body">
  	
  </div>
</div>
<?php $user_agent= $_SERVER['HTTP_USER_AGENT'];?>
<script type="text/javascript">
$('.close').click(function(){
	$('.modal-body').html('');
});
$('.btn').click(function(){
	$('.modal-body').html('');
	$('.modal-body').html('<video width="530" height="400" id="player1" src="" type="video/mp4" controls="controls"></video>');
	$("#player1").attr("src",$(this).attr("data"));
	<?php if(strpos((string)$user_agent, "Android")==false):?>
	MediaElement('player1', {success: function(me) {
//		me.play();
		
		me.addEventListener('timeupdate', function() {
			document.getElementById('time').innerHTML = me.currentTime;
		}, false);
		
		document.getElementById('pp')['onclick'] = function() {
			if (me.paused)
				me.play();
			else
				me.pause();
		};

	}});
	<?php else:?>
	function init() {
    	enableVideoClicks();
  	}
  	function enableVideoClicks() {
	    var videos = document.getElementsByTagName("video") || [];
	    for (var i = 0; i < videos.length; i++) {
	      // TODO: use attachEvent in IE
	      videos[i].addEventListener("click", function(videoNode) {
	        return function() {
	          videoNode.play();
	        };
	      }(videos[i]));
	    }
	  }
  	init();
  <?php endif;?>
});
</script>